package com.macro.mall.portal.service.impl;

import com.github.pagehelper.PageHelper;
import com.macro.mall.dto.BmsTourismProjectParam;
import com.macro.mall.mapper.BmsTourismProjectMapper;
import com.macro.mall.model.BmsTourismProject;
import com.macro.mall.model.BmsTourismProjectExample;
import com.macro.mall.portal.service.BmsTourismProjectService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

@Service
public class BmsTourismProjectServiceImpl implements BmsTourismProjectService {

    @Autowired
    private BmsTourismProjectMapper bmsTourismProjectMapper;

    @Override
    public List<BmsTourismProject> getList(BmsTourismProjectParam bmsTourismProjectParam) {
        Integer pageNum = bmsTourismProjectParam.getPageNum();
        Integer pageSize = bmsTourismProjectParam.getPageSize();
        if (Objects.nonNull(pageNum) && Objects.nonNull(pageSize)) {
            PageHelper.startPage(pageNum, pageSize);
        }
        BmsTourismProjectExample example = new BmsTourismProjectExample();
        BmsTourismProjectExample.Criteria criteria = example.createCriteria();
        criteria.andIsDelete(0);
        if (StringUtils.isNotBlank(bmsTourismProjectParam.getName())) {
            criteria.andNameLike("%" + bmsTourismProjectParam.getName() + "%");
        }
        if (Objects.nonNull(bmsTourismProjectParam.getIsExternal())) {
            criteria.andIsExternalEqualTo(bmsTourismProjectParam.getIsExternal());
        }
        example.setOrderByClause("create_time desc");
        List<BmsTourismProject> list = bmsTourismProjectMapper.selectByExample(example);
        return list;
    }


    @Override
    public BmsTourismProject getItem(Long id) {
        return bmsTourismProjectMapper.selectByPrimaryKey(id);
    }


}
